<?php
/**
 * Created by PhpStorm.
 * User: PanChaoZhi
 * Date: 2017/1/24
 * Time: 14:35
 */
namespace core\lib;

class route
{
    public $controller;
    public $action;

    public function __construct()
    {
        if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != '/') {
            $path = $_SERVER['REQUEST_URI'];
            //debug($path); // /index/index
            //debug(trim($path, '/')); // index/index
            $pathArr = explode('/', trim($path, '/'));
            if (isset($pathArr[0])) {
                $this->controller = $pathArr[0];
                unset($pathArr[0]);
            }
            if (isset($pathArr[1])) {
                $this->action = $pathArr[1];
                unset($pathArr[1]);
            } else {
                $this->action = 'index';
            }
            $count = count($pathArr) + 2;
            $i = 2;
            while ($i < $count) {
                if (isset($pathArr[$i + 1])) {
                    $_GET[$pathArr[$i]] = $pathArr[$i + 1];
                }
                $i = $i + 2;
            }

            //debug($_GET);
        } else {
            $this->controller = 'index';
            $this->action = 'index';
        }
    }
}